// UserAnswerRecordController.java
package com.exam.api.modules.exampaper.controller.manager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.exampaper.domain.TblUserAnswerRecord;
import com.exam.api.modules.exampaper.dto.AnswerRecordListDto;
import com.exam.api.modules.exampaper.dto.PageQuestionReviewDto;
import com.exam.api.modules.exampaper.mapper.TblUserAnswerRecordMapper;
import com.exam.api.modules.exampaper.service.TblUserAnswerRecordService;
import com.exam.api.modules.exampaper.vo.AnswerRecordVO;
import com.exam.api.modules.exampaper.vo.PageQuestionReviewVO;
import com.exam.api.modules.exampaper.vo.UserReviewAnswerItemVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户答题记录管理", description = "用户答题记录管理接口")
@RestController
@RequestMapping("/manager/userAnswerRecord")
@TinyResponse
public class TblUserAnswerRecordManagerController {

    @Resource
    private TblUserAnswerRecordService userAnswerRecordService;
    @Resource
    private TblUserAnswerRecordMapper userAnswerRecordMapper;

    @Operation(summary = "获取评审列表")
    @PostMapping("/reviewQuestionList")
    public IPage<PageQuestionReviewVO> reviewQuestionList(@RequestBody PageQuestionReviewDto dto) {
        return userAnswerRecordService.reviewQuestionList(dto);
    }

    @Operation(summary = "获取答卷列表")
    @PostMapping("/answerRecordList")
    public IPage<AnswerRecordVO> answerRecordList(@RequestBody AnswerRecordListDto dto) {
        return userAnswerRecordMapper.selectAnswerRecordList(Page.of(dto.getPageNum(), dto.getPageSize()), dto);
    }

    @Operation(summary = "获取答卷详情")
    @PostMapping("/answerRecordDetail/{recordId}")
    public List<UserReviewAnswerItemVO> answerRecordDetail(@PathVariable("recordId") Long recordId) {
        return userAnswerRecordService.answerRecordDetail(recordId);
    }


    @Operation(summary = "获取老师需要评审答案列表")
    @PostMapping("/list/{questionId}")
    public List<TblUserAnswerRecord> reviewAnswerList(@PathVariable("questionId") Long questionId) {
        return userAnswerRecordService
                .lambdaQuery()
                .eq(TblUserAnswerRecord::getQuestionId, questionId)
                .isNull(TblUserAnswerRecord::getScore)
                .orderByDesc(TblUserAnswerRecord::getCreateTime)
                .list();
    }

    @Operation(summary = "更新答题记录")
    @PostMapping("update")
    public void updateUserAnswerRecord(@RequestBody TblUserAnswerRecord userAnswerRecord) {
         userAnswerRecordService.updateById(userAnswerRecord);
    }
}
